import { reqGetSearchData } from '@/api/index'
const state = {
  searchData: {}
}

const mutations = {
  GETSEARCHDATA(state, searchData) {
    state.searchData = searchData
  }
}
// 简化仓库中的数据
const getters = {
  // 参数state：为当前仓库的 state
  goodsList(state) {
    return state.searchData.goodsList || []
  },
  trademarkList(state) {
    return state.searchData.trademarkList || []
  },
  attrsList(state) {
    return state.searchData.attrsList
  }
}
const actions = {
  // 获取search模块数据
  // 第二个参数为传递的数据，如果没传默认值为空对象
  async getSearchData ({ commit }, params = {}) {
    // 等待接口请求成功
    const result = await reqGetSearchData(params)
    if (result.code === 200) {
      commit('GETSEARCHDATA', result.data)
    }
  }
}

export default {
  state,
  mutations,
  getters,
  actions
}
